package cn.com.bluemoon.daps.api.model.factory;

import cn.com.bluemoon.daps.api.model.RemoteDataModelTableFieldService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.model.entity.DapDataModelTableField;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteDataModelTableFieldServiceFallbackFactory implements FallbackFactory<RemoteDataModelTableFieldService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteDataModelTableFieldServiceFallbackFactory.class);

    @Override
    public RemoteDataModelTableFieldService create(Throwable throwable) {
        log.error("模型字段服务调用失败:{}", throwable.getMessage());
        return new RemoteDataModelTableFieldService() {
            @Override
            public ResultBean<String> cleanRelation(String standardUniqueId) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "获取表字段信息失败");
            }

            @Override
            public ResultBean<Boolean> updateSetById(String id, DapDataModelTableField newT) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "更新表字段失败");
            }

            @Override
            public ResultBean<Boolean> dropById(DapDataModelTableField oldT, boolean logicDelete) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "删除表字段失败");
            }

            @Override
            public ResultBean<String> saveField(DapDataModelTableField newT) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "新增表字段失败");
            }
        };
    }
}
